## Replication file for the article
## "Terminating to Renegotiate? Strategic Exit from International Investment Treaties"
## Tuuli-Anna Huikuri, University of Zürich

## Review of International Political Economy
## July 2024

# Load packages and replication data

install.packages("pacman")
pacman::p_load(foreign, tidyr, dplyr, ggplot2, forcats, ggthemes, reshape2, forcats)

meltframe <- read.csv("/Users/huikuri/Dropbox/Terminating to Renegotiate/Replication/meltframe_RIPE.csv")
term <- read.csv("/Users/huikuri/Dropbox/Terminating to Renegotiate/Replication/term_RIPE.csv")

#Figure 1. 

#re-level factor by BIT termination type
term$ttype <- factor(x = term$ttype, levels = c("Renegotiation",
                                                "Exit",
                                                "Exit + new treaty"))
figure1 <- ggplot(term, aes(x = ttype, fill = factor(ttype))) +
  geom_bar() +
  theme_clean() +
  scale_fill_manual(
    values= c("grey68", "gray28", "grey3"),
    labels = c("Renegotiation", "Exit", "Exit + new treaty"),
    name = "Type of termination") +
  coord_flip() +
  xlab("Type of termination") +
  ylab("No. of BITs") +
  ggtitle("BIT terminations by type, 1972-2024") +
  theme(plot.title = element_text(hjust = 0.5), legend.position="right")
figure1 


#Figure 2: renegotiations, exit, and exit + new treaty by country

#re-level factor by countries with most BIT terminations
meltframe$iso3c <- factor(x = meltframe$iso3c, levels = c("ZAF", "ITA", "EGY", "ROU", "TUR", "DEU", "KOR", "CHN", "BOL", "IDN", "ECU", "IND"))

figure2 <- meltframe %>%
  ggplot(aes(x=iso3c, y =value, fill=variable)) +
  geom_bar(stat="identity", position=position_dodge(), width=0.8) +
  scale_fill_manual(values=c("grey68", "gray28", "grey3"), name = "Type of termination", 
                   labels = c("Exit", "Exit + new agreement", "Renegotiation")) +
  coord_flip() +
  theme_clean() +
  xlab("Country") +
  ylab("% of Terminations") +
  ggtitle("Countries with most BIT terminations \nby type of termination, 1972-2024") +
  theme(plot.title = element_text(hjust = 0.5), legend.position="bottom")
figure2


